package workers;

import java.util.concurrent.BlockingQueue;

import workerUIs.StepFrame;
import workflow.step.ImplementationStep;
import model.Software;

public class ImplementationStepWorker extends AbstractStepSwingWorker {

	private final BlockingQueue<Software> inputQueue;
	private final BlockingQueue<Software> outputQueue;
	protected final StepFrame nextFrame;

	public ImplementationStepWorker(StepFrame frame,
			final BlockingQueue<Software> inputQueue, final BlockingQueue<Software> outputImpl, final StepFrame nextFrame) {
		super(frame);
		this.inputQueue = inputQueue;
		this.outputQueue = outputImpl;
		this.nextFrame = nextFrame;
	}

	@Override
	protected Software doInBackground() throws Exception {
		Software software = this.inputQueue.take();
		this.software = software;
		new ImplementationStep().doStep(this.software);
		this.outputQueue.put(this.software);
		return this.software;
	}
	
	@Override
	protected void done() {
		super.done();
		if (inputQueue.isEmpty()) {
			getFrame().getNextButton().setEnabled(false);
		}
		this.nextFrame.getNextButton().setEnabled(true);
	}

}
